<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" href="../../css/animate.css">
		<link rel="stylesheet" href="../../iconfont/iconfont.css">
		<link rel="stylesheet" href="../../css/mescroll.css">
		<link rel="stylesheet" href="../../css/gloab.css">
		<title>支付确认</title>
		<style>
			.pay-div {
				width: 96%;
				margin: auto;
				padding: 0.1rem 0.1rem 0.4rem;
				border-bottom: 1px solid #e3e3e3;
			}

			.pay-div-content {
				width: 96%;
				margin: auto;
				padding: 0.3rem 0;
			}

			.pay-div-content span {
				display: inline-block;
				height: 0.45rem;
				/*line-height: 0.45rem;*/
				text-align: center;
				font-size: 0.3rem;
				color: #9e9e9e;
			}

			.pay-div-content img {
				display: inline-block;
				height: 0.6rem;
				text-align: center;
				font-size: 0.3rem;
				color: #9e9e9e;
			}

			.lt {
				float: left;
			}

			.rt {
				float: right;
			}

			.pay-button {
				width: 96%;
				margin: auto;
				height: 1rem;
				text-align: center;
				line-height: 1rem;
				color: #fff;
				font-size: 0.3rem;
				background: #1b80d4;
				border-radius: 0.1rem;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<div id="public-header">
				<div id="statusbar"></div>
				<header class="public-header">
					<div class="public-header-lf iconfont icon-fanhui" @click="api.closeWin()"></div>
					<div class="public-header-title"><span class="btn"></span>支付确认 <span class="btn"></span></div>
				</header>
			</div>
			<div class="pay-div">
				<div class="pay-div-content">
					<span class="lt">商品名:</span>
					<span class="rt" v-if="types==12">发布红包广告</span>
					<span class="rt" v-if="types==3">发布广告</span>
					<span class="rt" v-if="types==4">升级VIP</span>
					<span class="rt" v-if="types==5">升级站长</span>
					<span class="rt" v-if="types==6">置顶</span>
					<span class="rt" v-if="types==7">手动刷新</span>
					<span class="rt" v-if="types==8">自动刷新</span>
					<span class="rt" v-if="types==9">升级合伙人</span>
					<span class="rt" v-if="types==11">上头条</span>

				</div>
				<div class="pay-div-content">
					<span class="lt">账户信息:</span>
					<span class="rt">{{userInfo['nickname']}}</span>
				</div>
				<div class="pay-div-content">
					<span class="lt">付款金额:</span>
					<span class="rt" style="color:#f00;" v-if="userInfo['type_id']==2">站长特价￥{{release_price}}</span>
					<span class="rt" style="color:#f00;" v-if="userInfo['type_id']==1">VIP特价￥{{release_price}}</span>
					<span class="rt" style="color:#f00;" v-if="userInfo['type_id']==3">VIP特价￥{{release_price}}</span>
				</div>
			</div>
			<div class="pay-div">
				<div class="pay-div-content">
					<span class="lt">选择支付方式</span>
				</div>
			</div>
			<!-- <div class="pay-div" style="">
      <div class="pay-div-content" @click="pays(1)">
        <img class="lt" v-if="pay==1" style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/choose.png" alt="">
        <img class="lt" v-else style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/cancel.png" alt="">
        <img class="lt" style="width:0.8rem;height:0.8rem;line-height:0.3rem;margin:-0.3rem 0.1rem 0;" src="../../image/public/wechat.png" alt="">
        <span class="lt" style="line-height:0.3rem;color:#000;">微信支付</span>
      </div>
    </div> -->
			<div class="pay-div" style="clear:both" @click="pays(2)">
				<div class="pay-div-content">
					<img class="lt" v-if="pay==2" style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/choose.png"
					 alt="">
					<img class="lt" v-else style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/cancel.png"
					 alt="">
					<img class="lt" style="width:0.8rem;height:0.8rem;line-height:0.3rem;margin:-0.3rem 0.1rem 0;" src="../../image/public/alipay.png"
					 alt="">
					<span class="lt" style="line-height:0.3rem;color:#000;">支付宝</span>
				</div>
			</div>
			<div class="pay-div" style="clear:both" @click="pays(3)">
				<div class="pay-div-content" v-if="types==3||types==4||types==5||types==6||types==9||types==11||types==12">
					<img class="lt" v-if="pay==3" style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/choose.png"
					 alt="">
					<img class="lt" v-else style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/cancel.png"
					 alt="">
					<img class="lt " style="width:0.8rem;height:0.8rem;line-height:0.3rem;margin:-0.3rem 0.1rem 0;" src="../../image/public/price.png"
					 alt="">
					<span class="lt" style="line-height:0.3rem;color:#000;">余额支付</span>
					<span class="rt" style="line-height:0.3rem;">余额：<font style="color:#f00;">￥{{userInfo.balance}}</font>元</span>
				</div>
				<div class="pay-div-content" v-else>
					<img class="lt" v-if="pay==3" style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/choose.png"
					 alt="">
					<img class="lt" v-else style="width:0.35rem;height:0.35rem;line-height:0.3rem;" src="../../image/public/cancel.png"
					 alt="">
					<img class="lt " style="width:0.8rem;height:0.8rem;line-height:0.3rem;margin:-0.3rem 0.1rem 0;" src="../../image/public/price.png"
					 alt="">
					<span class="lt" style="line-height:0.3rem;color:#000;">积分支付</span>
					<span class="rt" style="line-height:0.3rem;">剩余积分：<font style="color:#f00;">￥{{integral}}</font></span>
				</div>
			</div>
			<div class="pay-div" style="border:none;margin-top:1rem;">
				<div class="pay-button" @click="putOut">立即支付</div>
			</div>
		</div>
	</body>
	<script src="../../script/api.js"></script>
	<script src="../../script/mescroll.js"></script>
	<script src="../../script/vue.js"></script>
	<script src="../../script/app.js"></script>
	<script src="../../script/jquery-1.8.3.min.js"></script>
	<script src="../../script/jsencrypt.js"></script>
	<script src="../../script/fastclick.js"></script>

	<script>
		var vm;
		var mescroll;
		apiready = function() {
			setBar("statusbar");
			setFont(750);
			startVue();
			$(".public-progress").fadeOut(1000);
			setTimeout(function() {
				$(".public-progress").css({
					"display": "none"
				});
			}, 1000);
		}

		function startVue() {
			vm = new Vue({
				el: "#app",
				data: {
					list: [],
					res: [],
					postList: [],
					types: api.pageParam.types,
					release_price: api.pageParam.release_price,
					balance: '',
					integral: '',
					pay: 3,
					userInfo: [],
					amount: api.pageParam.amount,
					price: api.pageParam.price,
					canvate: false,
				},
				created: function() {
					/* this.getPrice(); */
					this.getUserInfo();
				},
				methods: {
					doranking: function() {
						api.ajax({
							url: apiUrl + 'api/ranking/doranking',
							method: 'post',
							data: {
								values: {},
							}
						}, function(ret, err) {});
					},
					getUserInfo: function() {
						api.ajax({
							url: apiUrl + '/api/user/index',
							method: 'post',
							data: {
								values: {
									token: $api.getStorage('token'),
								},
							}
						}, function(ret, err) {
							console.log(JSON.stringify(ret))
							if (ret.code == 1) {
								vm.userInfo = ret.data;
							} else {
								vm.userInfo = ret.data;
							}
						});
					},
					pays: function(index) {
						vm.pay = index;
					},
					getPrice: function() {
						api.ajax({
							url: apiUrl + 'api/users/getPrice',
							method: 'post',
							data: {
								values: {
									uid: post_en($api.getStorage('uid')),
								},
							}
						}, function(ret, err) {
							if (ret.status) {
								vm.balance = ret.data['price'];
								vm.integral = ret.data['integral'];
							} else {
								msg(ret.msg);
							}
						});

					},
					//支付
					putOut: function() {
						if (vm.canvate) {
							return
						};
						if (vm.types == 12) {
							if (api.pageParam.price) {
								var content = '发布红包广告支付发布费用' + api.pageParam.price + '元';
							} else {
								var content = "";
							}
							if (api.pageParam.amount) {
								var content1 = '发布红包广告支付红包金额' + api.pageParam.amount + '元';
							} else {
								var content1 = "";
							}
						} else if (vm.types == 3) {
							var content = '发布广告支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 4) {
							var content = '升级VIP支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 5) {
							var content = '升级站长支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 6) {
							var content = '置顶1次支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 7) {
							var content = '手动刷新1次支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 8) {
							var content = '自动刷新支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 9) {
							var content = '升级合伙人支付' + api.pageParam.release_price + '元';
						} else if (vm.types == 11) {
							var content = '上头条支付' + api.pageParam.release_price + '元';
						}
						vm.canvate = true;
						if (vm.pay == 2) {
							api.ajax({
								url: apiUrl + '/api/user/pay',
								method: 'post',
								data: {
									values: {
										source_id: api.pageParam.ad,
										type: api.pageParam.type,
										token: $api.getStorage('token'),
										payment_code: 'alipay',
										money: vm.release_price,
									},
								}
							}, function(ret, err) {
								console.log(JSON.stringify(ret))
								setTimeout(function() {
									vm.canvate = false;
								}, 1000)
								if (ret.code == 1) {
									var aliPayPlus = api.require('aliPayPlus');
									aliPayPlus.payOrder({
										orderInfo: ret.data.data
									}, function(ret, err) {
										if (ret.code == 9000) {
											var dialogBox = api.require('dialogBox');
											if (vm.types == 300) {
												dialogBox.alert({
													texts: {
														content: '支付成功。是否继续发布',
														leftBtnTitle: '取消',
														rightBtnTitle: '确认'
													},
													styles: {
														bg: '#fff',
														w: 300,
														corner: 2,
														content: {
															color: '#000',
															size: 14
														},
														left: {
															marginB: 7,
															marginL: 20,
															w: 130,
															h: 35,
															corner: 2,
															bg: '#fff',
															size: 12
														},
														right: {
															marginB: 7,
															marginL: 10,
															w: 130,
															h: 35,
															corner: 2,
															bg: '#fff',
															size: 12
														}
													}
												}, function(ret) {
													var dialogBox = api.require('dialogBox');
													if (ret.eventType == 'left') {
														api.closeToWin({
															name: 'root'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.ranking();'
														});
														dialogBox.close({
															dialogName: 'alert'
														});
													} else if (ret.eventType == 'right') {
														dialogBox.close({
															dialogName: 'alert'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.ranking();'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.daohang(index=0);'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.getGuDingList();'
														});
														api.closeToWin({
														    name: 'root'
														});

													}
												});
											} else {
												console.log(api.pageParam.type)
												if(api.pageParam.type==4||api.pageParam.type==5){
													msg('支付成功,请到我发布的广告查看');
												}else{
													msg(ret.msg);
												}
												
												// setTimeout(function() {
												// 	api.closeToWin({
												// 		name: 'root'
												// 	});
												// 	api.execScript({
												// 		name: 'root',
												// 		frameName: 'home',
												// 		script: 'vm.daohang(index=0);'
												// 	});
												// 	api.execScript({
												// 		name: 'root',
												// 		frameName: 'home',
												// 		script: 'vm.getGuDingList();'
												// 	});
												// }, 1000);
												setTimeout(function(){
												  api.execScript({
												      name: 'root',
												      frameName: 'home',
												      script:'vm.daohang(index=0);'
												  });
												  api.closeToWin({
												      name: 'root'
												  });
												  api.execScript({
												      name: 'root',
												      script:'qhSelect(0);'
												  });
												},2000);
												// window.location.href = '../personal/personal.html';
											}
										} else if (ret.code == 8000) {
											alert('正在处理中，支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态');
										} else if (ret.code == 4000) {
											alert('订单支付失败');
										} else if (ret.code == 5000) {
											alert('重复请求');
										} else if (ret.code == 6001) {
											alert('用户中途取消支付操作');
										} else if (ret.code == 6002) {
											alert('网络连接出错');
										} else if (ret.code == 6004) {
											alert('支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态');
										}
									});
								} else {
									alert(JSON.stringify(err));
								}
							});
						} else if (vm.pay == 1) {
							api.ajax({
								url: apiUrl + 'api/pay/AppZhifus',
								method: 'post',
								data: {
									values: {
										uid: post_en($api.getStorage('uid')),
										release_price: post_en(api.pageParam.release_price), //发布广告所需费用
										pay: vm.pay, //支付方式
										types: vm.types, //类型：发布广告
										content: content + '（微信支付）',
										content1: content1,
										amount: vm.amount, //红包金额
										price: vm.price, //发布费用
										ad_id: api.pageParam.ad_id,
									},
								}
							}, function(ret, err) {
								if (ret.status) {
									var wxPayPlus = api.require('wxPayPlus');
									wxPayPlus.payOrder({
										apiKey: ret.data.apiKey,
										orderId: ret.data.orderId,
										mchId: ret.data.mchId,
										nonceStr: ret.data.nonceStr,
										timeStamp: ret.data.timeStamp,
										package: ret.data.package,
										sign: ret.data.sign
									}, function(ret, err) {
										if (ret.status) {
											if (vm.types == 3) {
												var dialogBox = api.require('dialogBox');
												dialogBox.alert({
													texts: {
														content: '支付成功。是否继续发布',
														leftBtnTitle: '取消',
														rightBtnTitle: '确认'
													},
													styles: {
														bg: '#fff',
														w: 300,
														corner: 2,
														content: {
															color: '#000',
															size: 14
														},
														left: {
															marginB: 7,
															marginL: 20,
															w: 130,
															h: 35,
															corner: 2,
															bg: '#fff',
															size: 12
														},
														right: {
															marginB: 7,
															marginL: 10,
															w: 130,
															h: 35,
															corner: 2,
															bg: '#fff',
															size: 12
														}
													}
												}, function(ret) {
													var dialogBox = api.require('dialogBox');
													if (ret.eventType == 'left') {
														api.closeToWin({
															name: 'root'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.ranking();'
														});
														dialogBox.close({
															dialogName: 'alert'
														});
													} else if (ret.eventType == 'right') {
														dialogBox.close({
															dialogName: 'alert'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.ranking();'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.daohang(index=0);'
														});
														api.execScript({
															name: 'root',
															frameName: 'home',
															script: 'vm.getGuDingList();'
														});
														api.closeToWin({
														    name: 'root'
														});

													}
												});
											} else {
												msg(ret.msg);
												setTimeout(function() {
													api.closeToWin({
														name: 'root'
													});
													api.execScript({
														name: 'root',
														frameName: 'home',
														script: 'vm.daohang(index=0);'
													});
													api.execScript({
														name: 'root',
														frameName: 'home',
														script: 'vm.getGuDingList();'
													});
												}, 500);
											}
										} else {
											alert(err);
										}
									});
								} else {
									api.toast({
										msg: ret.msg,
										duration: 2000,
										location: 'middle'
									});
								}
							});
						} else {
							console.log(api.pageParam.ad)
							api.ajax({
								url: apiUrl + '/api/user/pay',
								method: 'post',
								data: {
									values: {
										source_id: api.pageParam.ad,
										type: api.pageParam.type,
										token: $api.getStorage('token'),
										payment_code: 'balancepay',
										money: vm.release_price,
									},
								}
							}, function(ret, err) {
								console.log(JSON.stringify(ret));
								console.log(JSON.stringify(err));
								if (ret.code == 1) {
									if (vm.types == 300) {
										var dialogBox = api.require('dialogBox');
										dialogBox.alert({
											texts: {
												content: '支付成功。是否继续发布',
												leftBtnTitle: '取消',
												rightBtnTitle: '确认'
											},

											styles: {
												bg: '#fff',
												w: 300,
												corner: 2,
												content: {
													color: '#000',
													size: 14
												},
												left: {
													marginB: 7,
													marginL: 20,
													w: 130,
													h: 35,
													corner: 2,
													bg: '#fff',
													size: 12
												},
												right: {
													marginB: 7,
													marginL: 10,
													w: 130,
													h: 35,
													corner: 2,
													bg: '#fff',
													size: 12
												}
											}
										}, function(ret) {
											var dialogBox = api.require('dialogBox');
											if (ret.eventType == 'left') {
												api.closeToWin({
													name: 'root'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.daohang(index=0);'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.getGuDingList();'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.ranking();'
												});
												dialogBox.close({
													dialogName: 'alert'
												});
											} else if (ret.eventType == 'right') {
												dialogBox.close({
													dialogName: 'alert'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.ranking();'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.daohang(index=0);'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.getGuDingList();'
												});
												api.closeToWin({
												    name: 'root'
												});
											}
										});
									} else {
										if (ret.status) {
											msg(ret.msg);
											setTimeout(function() {
												api.closeToWin({
													name: 'root'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.ranking();'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.daohang(index=0);'
												});
												api.execScript({
													name: 'root',
													frameName: 'home',
													script: 'vm.getGuDingList();'
												});
											}, 500);
										} else {
											console.log(api.pageParam.type)
											if(api.pageParam.type==4||api.pageParam.type==5){
												msg('支付成功,请到我发布的广告查看');
											}else{
												msg(ret.msg);
											}
											
											setTimeout(function(){
											  api.execScript({
											      name: 'root',
											      frameName: 'home',
											      script:'vm.daohang(index=0);'
											  });
											  api.closeToWin({
											      name: 'root'
											  });
											  api.execScript({
											      name: 'root',
											      script:'qhSelect(0);'
											  });
											},2000);

										}
									}
								} else {
									msg(ret.msg);
								}
							});
						}
					},
				}
			})
		}
	</script>
</html>
